#!/usr/bin/perl
use strict;
use warnings;

# DET NOM ADJ? PRP DET? NOM ADJ?

my (@words, @ordre, @sequences);
my($mot, $cat, $lemme, $phrase, $taille, $max, $i, $start);

@words = ();
@sequences = ();
@ordre = ();
push @ordre, "DET";
push @ordre, "NOM";
push @ordre, "PRP";
push @ordre, "NOM";

$start=1;

open (TT, " zcat \$CORPUS | \$TTDIR/tree-tagger-french |") || die $!;
while (my $ligne = <TT>){
	chomp($ligne);
	if($ligne=~ /^(.*)\t(.*)\t(.*)$/){
		$mot=$1; $cat=$2; $lemme=$3;
		if ($start eq 0) {
			@words = ();
		}
		$taille = scalar @words;
		if ($cat eq $ordre[$taille]) {
			push @words, $mot;
			$start=1;
		}
		else {
			$start=0;
		}
		$taille = scalar @words;
		$max = scalar @ordre;
		if ($taille eq $max) {
			$phrase="";
			for $i (0..$#words) {
  				$phrase+=$words[$i]." ";
			}
			push @sequences, $phrase;
			@words = ();
		}
	}
}

printf "\n\nRESULTAT : \n";

for $i (0..$#sequences) {
  	printf $sequences[$i]."\n";
}